<template>
  <!-- 选择题 -->
  <div class="choice-question">
    <div class="question-title">
      <p class="title-left">
        <span class="red-text">*</span>
        <span>{{ title }} <span class="gray-text">[单选]</span></span>
      </p>
      <p 
        :class="{'is-end': isEnd}"
        class="title-right">{{ '未完成' }}</p>
    </div>
    <div class="question-list">
      <div class="question-item" 
        @click="toggleItem(index, item.name)"
        v-for="(item, index) in list" :key="index">
        <img 
          v-if="value === item.name"
          src="@/assets/image/question-check-img.png" 
          alt="" class="img"/>
        <img 
          v-else
          src="@/assets/image/question-uncheck-img.png" 
          alt="" class="img"/>
        <span>{{ item.name }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    questionIndex: {
      type: Number,
      default: 0
    },
    title: {
      type: String,
      default: ''
    },
    isEnd: {
      type: Boolean,
      default: false
    },
    value: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  methods: {
    // TODO 这里需要实时提交表单
    toggleItem (index, name) {
      this.$emit('pushValue', {index: this.questionIndex, value: name})
    }
  }
}
</script>

<style scoped>
.gray-text {
  color: #CCCCCC;
}
.question-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4.27vw;
}
.title-right {
  width: 16.53vw;
  height: 5.87vw;
  line-height: 5.87vw;
  text-align: center;
  border-radius: 2.93vw;
  background: #FF7628;
  font-family: Source Sans Pro;
  font-size: 3.2vw;
  font-weight: 600;
  color: #FFFFFF;
  flex-shrink: 0;
}
.question-item {
  display: flex;
  align-items: center;
  margin-bottom: 3.2vw;
}
.img {
  width: 4.27vw;
  height: 4.27vw;
  margin-right: 2.13vw;
}
.red-text {
  color: #EE0A24;
  margin-right: 0.8vw;
  font-family: Source Sans Pro;
  font-size: 4.27vw;
}
.choice-question {
  width: 96vw;
  margin: 0 auto 3.2vw;
  box-sizing: border-box;
  padding: 4.27vw 4.27vw 6.4vw;
  background: #fff;
  border-radius: 2.13vw;
  font-family: Source Sans Pro;
  font-size: 4.27vw;
  font-weight: 600;
  color: #3D3D3D;
}
.is-end {
  background: #008924;
}
</style>